package com.yb0os1.decorator;

import com.yb0os1.decorator.inputstream.BufferInputStream;
import com.yb0os1.decorator.inputstream.RecordReadInputStream;

import java.io.File;
import java.io.FileInputStream;

public class Main {
    public static void main(String[] args) {
       /* HistorySet<Integer> set = new HistorySet<>(new HashSet<>());
        set.add(1);
        set.add(2);
        set.add(3);
        set.add(4);
        set.add(5);

        System.out.println(set);
*/
        File file = new File("111.pdf");
        try (
                FileInputStream fileInputStream = new FileInputStream(file);
                RecordReadInputStream recordReadInputStream = new RecordReadInputStream(fileInputStream);
                BufferInputStream bufferInputStream = new BufferInputStream(fileInputStream)
        ) {
            long start = System.currentTimeMillis();
//            long count = 0;
//            while (true){
//                int read = fileInputStream.read();
//                count++;
//                if (read == -1){
//                    break;
//                }
//            }
            long end = System.currentTimeMillis();
            System.out.println("fileInputStream 花费" + (end - start) + "ms");//花费87821ms
//            System.out.println("fileInputStream 读取次数" + count);


            start = System.currentTimeMillis();
            while (true) {
                int read = recordReadInputStream.read();
                if (read == -1) {
                    break;
                }
            }
            end = System.currentTimeMillis();
            System.out.println("bufferInputStream 花费" + (end - start) + "ms");//花费70ms
            System.out.println("recordReadInputStream 读取次数" + recordReadInputStream.getCount());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

